Public Class GlobalEventListener
    Implements System.Windows.Forms.IMessageFilter


    Public Sub New()
        mLastWindowEventTime = Now
    End Sub

    Public Function PreFilterMessage(ByRef m As Message) As Boolean Implements System.Windows.Forms.IMessageFilter.PreFilterMessage
        '        Debug.WriteLineIf(AppTrace, m)

        If (Array.IndexOf(mWinEvents, m.Msg) <> -1) Then
            mLastWindowEventTime = Now
            'Console.WriteLine(m.ToString)
        End If

        Return False
    End Function

    Public ReadOnly Property LastWindowEventTime() As DateTime
        Get
            Return mLastWindowEventTime
        End Get
    End Property

    Private mLastWindowEventTime As DateTime

    '{WM_KEYUP, WM_KEYDOWN, WM_MOUSEMOVE,WM_LBUTTONDOWN,WM_LBUTTONUP,WM_RBUTTONDOWN,WM_RBUTTONUP,WM_MBUTTONDOWN,WM_MBUTTONUP,WM_MOUSEWHEEL}
    Private mWinEvents() As Integer = {&H100, &H101, &H201, &H202, &H203, &H204, &H207, &H208, &H20A}
End Class
